﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//using SomethingSpacialClassLib.Web;
using SomethingSpacial.Web;
using System.Windows.Ria;
using SomethingSpacial.Helpers;
using SomethingSpacial.ViewModel;

namespace SomethingSpacial.Views.Admin
{
    public partial class EventAdd : ChildWindow
    {
        public Events NewEvent { get; set; }
        SomethingSpacialContext domainContext = new SomethingSpacialContext();

        public EventAdd()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(EventAdd_Loaded);
            this.Closed += new EventHandler(EventAdd_Closed);
 
        }

        void EventAdd_Closed(object sender, EventArgs e)
        {
            if (this.DialogResult != true)
            {
                NewEvent = null;
                addEventDataForm.CancelEdit();
            }
        }

        void EventAdd_Loaded(object sender, RoutedEventArgs e)
        {
                     
            NewEvent = new Events();
       
        }

        //public void LocationsLoaded(LoadOperation<Locations> lo)
        //{
        //    //Do something here now that the ComboBox is Loaded
        //    //RIAServicesHelper.InitializeComboBoxIndex("comboBoxLocations", addEventDataForm);    //Setting the ListIndex = first item
        //}

        //public void UserGroupsLoaded(LoadOperation<UserGroups> lo)
        //{
        //    //Do something here now that the ComboBox is Loaded
        //  //RIAServicesHelper.InitializeComboBoxIndex("comboBoxUserGroups", addEventDataForm);    //Setting the ListIndex = first item
        //}


        void InitializeComboBoxIndex(string comboBoxName, DataForm dataFormCurrent)
        {
            ComboBox comboItems = (ComboBox)dataFormCurrent.FindNameInContent(comboBoxName);
            if (comboItems.Items.Count > 0 )
            {
                comboItems.SelectedIndex = 0;
            }

        }
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {

          //  NewEvent.EVT_Start_Date = Convert.ToDateTime(NewEvent.EVT_Start_Date.ToShortDateString() + " " + " 6:30 pm");



            // Store Away User Group ID (there must be a more automated way of doing this.  Isn't it already bound to the DataField??? (ds 0830)
            ComboBox comboItems = (ComboBox)addEventDataForm.FindNameInContent("comboBoxUserGroups");
            UserGroups userGroupSelected = (UserGroups)comboItems.SelectedItem;
            NewEvent.EVT_UserGroup = userGroupSelected.UG_Id;


            comboItems = (ComboBox)addEventDataForm.FindNameInContent("comboBoxLocations");
             Locations locationSelected = (Locations)comboItems.SelectedItem;
             NewEvent.EVT_Location = locationSelected.LOC_Id;
            addEventDataForm.CommitEdit();	
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }



    }
}

